package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteBookCategoryOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocCategoryDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.VocCategoryCommand;
import com.cskaoyan.wordmemorize.service.VocCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/voc")
public class AdminVocCategoryController {


    @Autowired
    VocCategoryService vocCategoryService;

    @GetMapping("category/list")
    public Result<PageDTO<VocCategoryDTO>> getCategoryList(PageRequest pageRequest) {

        PageDTO<VocCategoryDTO> bookCategories
                = vocCategoryService.getBookCategories(pageRequest);


        return Result.ok(bookCategories);
    }

    @GetMapping("category")
    public Result<VocCategoryDTO> getCategory(Long categoryId) {
        VocCategoryDTO bookCategory = vocCategoryService.getBookCategory(categoryId);
        return Result.ok(bookCategory);
    }
    @PostMapping("category")
    public Result<Object> addCategory(@RequestBody VocCategoryCommand vocCategoryCommand) {
        return Result.ok(vocCategoryService.addBookCategory(vocCategoryCommand));
    }

    @PutMapping("category")
    public Result<Object> updateCategory(@RequestBody VocCategoryCommand vocCategoryCommand) {
        vocCategoryService.updateBookCategory(vocCategoryCommand);
        return Result.ok("更新成功");
    }

    @DeleteMapping("category/{categoryId}")
    public Result<DeleteBookCategoryOperateDTO> deleteCategory(@PathVariable Long categoryId) {
        return Result.ok(vocCategoryService.deleteBookCategory(categoryId));
    }

    @DeleteMapping("categories")
    public Result<List<DeleteBookCategoryOperateDTO>> deleteCategorys(@RequestBody BatchDeleteCommand command) {
        return Result.ok(vocCategoryService.deleteBookCategories(command));
    }
}
